﻿using CarRental.Helpers;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace CarRental.View {
    public partial class SearchCar : System.Web.UI.Page {
        protected void Page_Load(object sender, EventArgs e) {
            if (!IsPostBack) {
                //EntityDataSource_SearchCar.AutoGenerateWhereClause = true;

                if (Shared.LoginInfo.UserType == "ADMIN") {
                    gvCarLst.Columns[0].Visible = true;
                } else {
                    gvCarLst.Columns[0].Visible = false;
                }

                ddlDepot.DataSource = new CarRental.Helpers.OptionItems.DepotLst(true);
                ddlDepot.DataValueField = "Key";
                ddlDepot.DataTextField = "Title";
                ddlDepot.DataBind();

                ddlDrivetrains.DataSource = new CarRental.Helpers.OptionItems.DriveTrainsLst(true);
                ddlDrivetrains.DataValueField = "Key";
                ddlDrivetrains.DataTextField = "Title";
                ddlDrivetrains.DataBind();

                ddlColor.DataSource = new CarRental.Helpers.OptionItems.ColorLst(true);
                ddlColor.DataValueField = "Key";
                ddlColor.DataTextField = "Title";
                ddlColor.DataBind();

                ddlCarType.DataSource = new CarRental.Helpers.OptionItems.CarTypeLst(true);
                ddlCarType.DataValueField = "Key";
                ddlCarType.DataTextField = "Title";
                ddlCarType.DataBind();

            }

        }

        protected void btnSearchCar_Click(object sender, EventArgs e) {
            
        }

        protected void gvCarLst_RowCommand(object sender, GridViewCommandEventArgs e) {
            if (e.CommandName == "Edit") {
                int index = Convert.ToInt32(e.CommandArgument);
                GridViewRow row = gvCarLst.Rows[index];
                //int ServerID = Convert.ToInt32(gvUser.DataKeys[index].Value);
                var carId = row.Cells[1].Text;

                Response.Redirect("~/View/Car/EditCar.aspx?CarId=" + carId); 
            }
        } 
    }
}